import { defineStore } from 'pinia';
import { ref } from 'vue';
// 定义数据类型
interface dataInfo {
    lang?: string;
}

// 定义 Store
export const useMemberStore = defineStore(
    'member',
    () => {
        const dataInfo = ref<dataInfo>({});

        // 设置信息
        const setDataInfo = (info: dataInfo) => {
            dataInfo.value = { ...dataInfo.value, ...info };
        };

        // 清理信息（退出登录）
        const clearDataInfo = () => {
            dataInfo.value = {};
        };

        // 记得 return
        return { dataInfo, setDataInfo, clearDataInfo };
    },
    {
        // 小程序端配置
        persist: {
            storage: {
                getItem(key) {
                    return uni.getStorageSync(key);
                },
                setItem(key, value) {
                    uni.setStorageSync(key, value);
                }
            }
        }
    }
);
